<?php

/**
 * Created by JetBrains PhpStorm.
 * User: superx
 * Date: 12-10-11
 * Time: 上午10:31
 * To change this template use File | Settings | File Templates.
 */
abstract class Vo_Basic_Element extends Core_ArrayObject
{
    public static function getUTCTime($datetime)
    {
        return date('r', strtotime($datetime));
    }

    public static function processArray(array $list)
    {
        $ret = array();
        foreach ($list as $singleElement) {
            if ($singleElement && ($li = static::process($singleElement))) {
                $ret[] = $li;
            }
        }
        return $ret;
    }

    /**
     * @param array $list
     * @param       $length
     * @param bool $offset
     * @return Vo_Basic_List
     */
    public static function processList(array $list, $length, $offset = false)
    {
        $ret = new Vo_Basic_List();

        if ($offset === false) {
            //id < ? offset
            $ret->hasMore = count($list) > $length;
            foreach ($list as $single) {
                $singleItem = static::process($single);
                if (!$singleItem) {
                    continue;
                }
                $ret->list[] = $singleItem;
                list (, $v) = each($singleItem);
                $ret->start = $v;
                if (count($ret->list) == $length) {
                    return $ret;
                }
            }

        } else {
            //number offset
            $ret->hasMore = count($list) > $length;
            $ret->start = $offset;
            foreach ($list as $single) {
                $singleItem = static::process($single);
                $ret->start++;
                if (!$singleItem) {
                    continue;
                }
                $ret->list[] = $singleItem;
                if (count($ret->list) == $length) {
                    return $ret;
                }
            }
        }
        return $ret;
    }

}
